
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>业务管理</cite></a>
    <a><cite>下级商户</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-tab layui-tab-brief">
      <ul class="layui-tab-title">
        <li class="layui-this">下级商户列表</li>
      </ul>
      <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
          <div class="layui-row">
            <div class="layui-form" style="float:right;">
              <div class="layui-form-item" style="margin:0;">
                <div class="layui-input-inline">
                  <input type="text" name="mchId" id="searchMchId" placeholder="商户ID" autocomplete="off" class="layui-input">
                </div>
                <a id="search" class="layui-btn" data-type="reload"><i class="layui-icon layui-icon-search"></i>搜索</a>
              </div>
            </div>
          </div>
          <div class="layui-row">
            <div class="layuiAdmin-btns" style="margin-bottom: 10px;">
              <a class="layui-btn mchAddBtn"><i class="layui-icon layui-icon-add-1"></i>新增</a>
            </div>
          </div>
          <table id="XxPay_Mgr_Merchant_dataAll" lay-filter="XxPay_Mgr_Merchant_dataAll"></table>
        </div>

      </div>
    </div>
  </div>
</div>

<script>
  layui.use(['admin', 'table', 'util'], function(){
    var $ = layui.$
            ,admin = layui.admin
            ,table = layui.table
            ,element = layui.element
            ,form = layui.form
            ,view = layui.view;

    element.render('breadcrumb', 'breadcrumb');

    var tplStatus = function(d){
      if(d.status == -1) {
        return "<span style='color: orange'>等待审核</span>";
      }else if(d.status == -2) {
        return "<span style='color: red'>审核不通过</span>";
      }else if(d.status == 0) {
        return "<span style='color: rebeccapurple'>停止</span>";
      }else if(d.status == 1) {
        return "<span style='color: darkgreen'>启用</span>";
      }
    };

    var tplEdit = function(d){
      return "<a class='layui-btn layui-btn-primary layui-btn-xs' lay-event='merchantDetail'><i class='layui-icon layui-icon-about'></i>查看商户</a>" +
              "<a class='layui-btn layui-btn-primary layui-btn-xs' lay-event='payPassageConfig'><i class='layui-icon layui-icon-template-1'></i>支付通道</a>";
    };

    //商户列表
    table.render({
      elem: '#XxPay_Mgr_Merchant_dataAll'
      ,url: layui.setter.baseUrl + '/mch_info/list' //列表接口
      ,where: {
          access_token: layui.data(layui.setter.tableName).access_token
      }
      ,id: 'tableReload'
      ,page: true
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field: 'mchId', title: '商户ID'}
        ,{field: 'name', title: '商户名称'}
        ,{field: 'status', title: '状态', templet: tplStatus}
        ,{field: 'createTime', title: '时间', width: 200, templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'}
        ,{field: 'edit', title: '操作', fixed: "right", width: 200, templet: tplEdit }
      ]]
      ,skin: 'line'
    });

    //监听工具条
    table.on('tool(XxPay_Mgr_Merchant_dataAll)', function(obj){
      var data = obj.data;
      if(obj.event === 'merchantDetail'){
        view.xxpayPopup("查看商户信息", "biz/merchant/mch_view", {mchId: data.mchId}, {btn:false});
      } else if(obj.event === 'payPassageConfig'){
          view.xxpayPopup("查看商户支付通道", "biz/pay_passage/index", {mchId: data.mchId}, {btn:false});
      }

    });

    // 搜索
    var $ = layui.$, active = {
      reload: function(){
        var mchId = $('#searchMchId').val();
        //执行重载
        table.reload('tableReload', {
          page: {
            curr: 1 //重新从第 1 页开始
          }
          ,where: {
            mchId: mchId
          }
        });
      }
    };
    $('#search').on('click', function() {
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

    $(".mchAddBtn").click(function(){
        view.xxpayPopup("新增商户", "biz/merchant/mch_add");
    });

    // 渲染表单
    form.render();
  });
</script>